(load 'aplicar)
(load 'ambiente)

(defun eval (exp amb)
	(if (null exp) nil
		(if (atom exp) (if  (numberp exp) exp
					(buscar exp amb)
				)
				 (cond ((eq (car exp) 'and) (if (eval (nth 1 exp) amb) (eval (nth 2 exp) amb) nil))
					   ((eq (car exp) 'or) (if (eval (nth 1 exp) amb) T (eval (nth 2 exp) amb)))
					   ((eq (car exp) 'quote) (cadr exp))
					   ((eq (car exp) 'if) (if (eval (nth 1 exp) amb) (eval (nth 2 exp) amb) (eval (nth 3 exp) amb)))
					   ((eq (car exp) 'cond) (evalcond (cdr exp) amb))
				   
					   ( T (aplicar (eval (car exp) amb) (listaargeval (cdr exp) amb) amb))
				 )
		 )
	)
)

(defun evalcond (exp amb)
     (if (null exp) nil
         (if (eval (caar exp) amb) (eval (cadar exp) amb)
             (evalcond (cdr exp) amb)
         )
     )
)

(defun listaargeval (args amb)
     (mapcar '(lambda (x) (eval x amb)) args)
)
